package Client;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;

import demoSocket.MyClient;
import demoSocket.frameClient1;
import demoSocket.frameClient.connect;

public class FrameLogin extends JFrame
{
	private JTextField tfUserName;
	private JButton btnStart;
	private JList lsUserName;
	private JPanel pnAdd;
	
	public frameClient()
	{
		super("Chat");
		initComponent();
	}
	
	private void initComponent()
	{
		setBounds(200,300,300,200);
		setResizable(false);
		Container c = getContentPane();
		c.setLayout(new BorderLayout());
		pnAdd = new JPanel(new FlowLayout());
		tfUserName = new JTextField(20);
		pnAdd.add(tfUserName);
		btnStart = new JButton("Bắt Đầu");
		btnStart.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				EventQueue.invokeLater(new Runnable(){
				@SuppressWarnings("resource")
				public void run()
				{
					if(tfUserName.getText().equals(""))
					{
						JOptionPane.showMessageDialog(tfUserName, "UserName can not null");
						return;
						//btnStart.setEnabled(false);
					}
					SwingUtilities.invokeLater(new Runnable(){

						@Override
						public void run() {
							// TODO Auto-generated method stub
							frameClient1 test = new frameClient1();
							test.setVisible(true);
							dispose();
							connect cn = new connect();
							cn.start();
						}						
					});
				}
			});
		}
	});
		pnAdd.add(btnStart, BorderLayout.CENTER);
		c.add(pnAdd);
	}
	/*class connect extends Thread
	{
		public void run()
		{
		String str;
		Scanner scanner = null;
		MyClient ms = new MyClient();
		ms.start();
		while(true){
		scanner = new Scanner(System.in);
		str = scanner.nextLine();
		ms.send2Server(str);}
		}
	}*/
}
